import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/productOperation/list',
  save='/productOperation/add',
  listNoConcat = '/productOperation/listNoConcat',
  deleteOne = '/productOperation/delete',
  deleteBatch = '/productOperation/deleteBatch',
  sort = '/productOperation/sort'
}
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});
/**
 * 列表接口,未关联的产品
 * @param params
 */
export const listNoConcat = (params) =>
  defHttp.get({url: Api.listNoConcat, params});

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.post({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量取消关联事件
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const add = (params, handleSuccess) => {
  return defHttp.post({url: Api.save, params}).then(() => {
    handleSuccess();
  });
};
  /**
   * 排序
   * @param params
   */
  export const sort = (params, handleSuccess) => {
    return defHttp.post({url: Api.sort, params},{joinParamsToUrl: true}).then(() => {
      handleSuccess();
    });
};
